import { defineStore } from "pinia";

export const userStore = defineStore("userStore", {
    state: () => ({
        age: 18,
        name: "airvip"
    }),
    getters: {
        changeAge: (state) => {
            return state.age + 1
        }
    },
    actions: {
        updateAge(age: number) {
            this.age = age
        }
    },
    // 开启数据缓存
    persist: {
        enabled: true,
        // 默认是 sessionStore,启用localStorage
        strategies: [{
            key: 'userStore',
            storage: localStorage,
            // 默认都进行持久化，可以 paths 配置一些要持久化的
            // paths: ['age']
        }]
    }
})